#ifndef _BATTLE_SERVER_H_
#define _BATTLE_SERVER_H_

#include "Common.h"
#include "BSSocket.h"
#include "BufferPools.h"
#include "Threading/ThreadStarter.h"
#include "Threading/QueueThreadPool.h"
#include "Database/DatabaseEnv.h"
#include "Threading/Mutex.h"
#include "Object.h"
#include "WorldPacket.h"

#include <map>



class ProtocolsManager;

class Database;
class ScriptMgr;


#define  DEFAULT_SERVER_SOCKET_POOL_SIZE		2048  //default for max client connect
class SocketEngine;
class BSSocketPtr;
class BSSocketManager;

class  BattleServer : public Singleton<BattleServer>
{
public:
	BattleServer();
	~BattleServer();

	bool	Start(int argc, char ** argv);
	bool	Shutdown(void);

	//internal update check	
	bool	Run(void);

	bool 		m_ShutdownEvent;
	uint32	  	m_ShutdownTimer;

	static void _OnSignal(int s);
	void _HookSignals();
	void _UnhookSignals();
	
	static void Stop(void);
	
	
	const uint32 & 	getServerID(void)	{	return m_serverID;	}
	void setServerID(const uint32 &id)	{	m_serverID = id;	}

	const uint32 & 	getServerGroupID(void)	{	return m_serverGroupID;	}
	void setServerGroupID(const uint32 &id)	{	m_serverGroupID = id;	}
private:
	bool _StartDB(void);
	bool _StopDB(void);

	volatile static bool m_running;

	void ShowStats(void);

	//socket engine
	BSSocketManager * m_BSSocketMgr;

	//script manager
	ScriptMgr 	* m_scriptMgr;

	//Mutex		m_MainLock;

	uint32		m_client_num_limit;
	uint32	m_serverID;	
	uint32	m_serverGroupID;	

};


#define   sBattleServer	  BattleServer::getSingleton()



#endif
